<include file="Public/head" />
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<style type="text/css">
    .his_1,.his_2{display: block;margin-top: 5px;}
    .his_2{color: #303030;float: left;margin-left: 7px;}
    .custom_search{display: block;margin-top: 10px;width:100%;height:25px;}
    #recommend {
        -moz-appearance: none;
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}paimai/yunying/images/sanjiao.jpg") no-repeat scroll 130px 5px;
        border: 1px solid #d7d7d7;color: #666;float: left; height: 25px;line-height: 25px;margin-left:10px;text-align: center;width: 150px;}
    .history_deal{display: block;margin-top: 10px;}
    .yuSuo .suoDian{width:148px}
    #search{margin-top:5px;}
    .chexing{z-index: 0;}
</style>
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="nrgl.lscj" />
    <div class="mianR">
        <div class="yuSuo clearfix">
            <div class="history_deal clearfix">
                <form id="searchFrom">
                    <div class="his_1">
                        <input type="text" id="order_no" name="order_no" placeholder="请输入拍单编号" value="" class="suoDian" />
                        <div class="car_select clearfix">
                            <script src="{:get_style_cdnurl()}paimai/cheshan/js/model_select.js" type="text/javascript"></script>
                        </div>
                    </div>
                    <div class="his_2">
                        <select id="recommend" name="is_recommend" style="margin-right: 30px;">
                            <option value="">全部状态</option>
                            <option value="1">已推荐</option>
                            <option value="2">未推荐</option>
                        </select>
                        <input type="text" id="start_time" name="start_time" value="" readonly placeholder="开始时间" /><em></em>
                        <input type="text" id="end_time" name="end_time" value="" readonly placeholder="结束时间" style="margin-right: 10px;"/> 
                    </div>
                </form> 
                <input type="button" onclick="search();" id="search" value="搜索" class="suoSou">
            </div>

        </div>
        <div class="yuList">
            <div class="listBox" id="listBox"></div>
        </div>
    </div>
    <script type="text/javascript">
        $(".yuSuo .pingXia input").css('width','142px');
        $("#start_time").ymdateplugin({
            changeMonth: true,
            changeYear: true
        });
        $("#end_time").ymdateplugin({
            changeMonth: true,
            changeYear: true
        });
        get_list();
        function get_list() {
            var url = mkUrl();
            $.get("/HistoryDeal/history_deal_list", encodeURI(url), function (data) {
                $("#listBox").html(data);
            }, "html");
        }
        function get_page(p) {
            var url = mkUrl();
            url += "&p=" + p;
            $.get("/HistoryDeal/history_deal_list", encodeURI(url), function (data) {
                $("#listBox").html(data);
            }, "html");
        }
        function search() {
            var url = mkUrl();
            $.get("/HistoryDeal/history_deal_list", encodeURI(url), function (data) {
                $("#listBox").html(data);
            }, "html");
        }
        function mkUrl() {
            var url = "";
            var order_no = $("#order_no").val();
            var brand_id = $('.pingXiaCo').attr('brand_id');
            var series_id = $('.cheXiaCo').attr('series_id');
            var model_id = $('.cheXiaCo1').attr('model_id');
            var is_recommend = $("#recommend").val();
            var start_time = $("#start_time").val();
            var end_time = $("#end_time").val();
            if (order_no) {
                url += '&order_no=' + order_no;
            }
            if (brand_id) {
                url += '&brand_id=' + brand_id;
            }
            if (series_id) {
                url += '&series_id=' + series_id;
            }
            if (model_id) {
                url += '&model_id=' + model_id;
            }
            if (is_recommend) {
                url += '&is_recommend=' + is_recommend;
            }
            if (start_time) {
                url += '&start_time=' + start_time;
            }
            if (end_time) {
                url += '&end_time=' + end_time;
            }
            return url;
        }
        
        
        function confirm_popup(order_id, is_recommend) {
            if (is_recommend == '1') {
                msg = "确认推荐该拍单？";
                htext = "推荐拍单";
            } else {
                msg = "确认取消推荐该拍单？";
                htext = "取消推荐拍单";
            }
            text = '<div style="color:red">' + msg + '</div>';
            var html = '<div class="chenggong1">\n\
                        <span class="paidan"><h3>' + htext + '</h3>' + text + '</span>\n\
                        <div class="shenhei-btn"><input type="button" value="确定" class="determine" />\n\
                        <input type="button" value="取消" class="cancel" onclick="colse_hide()" />\n\
                        </div></div>';
            $(".yunBei").css("display", "block");
            $(document.body).append(html);
            $(".chenggong1").fadeIn();
            confirm(order_id,is_recommend);
        }
        function confirm(order_id,is_recommend) {
            $('.determine').click(function () {
                colse_hide();
                change_recommend_status(order_id,is_recommend);
            });
        }
        /**
         * 推荐、取消操作
         * @param {type} c_id
         * @param {type} status
         * @returns {Boolean}
         */
        function change_recommend_status(order_id,is_recommend) {
            var post_data = {order_id: order_id, is_recommend: is_recommend};
            $.post('/HistoryDeal/is_recommend_post', post_data, function (res) {
                if (res.code == 200) {
                    delay_alert('操作成功!');
                    setTimeout(function () {
                        window.location.reload();
                    }, 500);
                } else {
                    delay_alert(res.msg);
                }
            }, 'json');
            return false;
        }
    </script>
    <include file="Public/foot" />